/**
 ******************************************************************************
 * @file    bsp_led.c
 * @author  Iron
 * @date    2020-01-01
 * @version v1.0
 * @brief   bsp_led c file
 */

/* Private includes ----------------------------------------------------------*/
#include "bsp_led.h"

/* Private typedef -----------------------------------------------------------*/
typedef struct _bsp_led_cfg
{
    uint32_t port;
    uint16_t pin;
} bsp_led_cfg_t;

/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/

int32_t bsp_led_get(int32_t led_id)
{
    int32_t state = BSP_LED_OFF;

    switch (led_id)
    {
    case 0:
        state = GPIOB_ReadPortPin(GPIO_Pin_0);
        state = state ? BSP_LED_ON : BSP_LED_OFF;
        break;
    case 1:
        state = GPIOB_ReadPortPin(GPIO_Pin_4);
        state = state ? BSP_LED_OFF : BSP_LED_ON;
        break;
    case 2:
        state = GPIOB_ReadPortPin(GPIO_Pin_7);
        state = state ? BSP_LED_OFF : BSP_LED_ON;
        break;
    }

    return state;
}

int32_t bsp_led_on(int32_t led_id)
{
    switch (led_id)
    {
    case 0:
        GPIOB_SetBits(GPIO_Pin_0);
        break;
    case 1:
        GPIOB_ResetBits(GPIO_Pin_4);
        break;
    case 2:
        GPIOB_ResetBits(GPIO_Pin_7);
        break;
    }

    return led_id;
}

int32_t bsp_led_off(int32_t led_id)
{
    switch (led_id)
    {
    case 0:
        GPIOB_ResetBits(GPIO_Pin_0);
        break;
    case 1:
        GPIOB_SetBits(GPIO_Pin_4);
        break;
    case 2:
        GPIOB_SetBits(GPIO_Pin_7);
        break;
    }

    return led_id;
}

int32_t bsp_led_toggle(int32_t led_id)
{
    switch (led_id)
    {
    case 0:
        GPIOB_InverseBits(GPIO_Pin_0);
        break;
    case 1:
        GPIOB_InverseBits(GPIO_Pin_4);
        break;
    case 2:
        GPIOB_InverseBits(GPIO_Pin_7);
        break;
    }

    return led_id;
}

int32_t bsp_led_init(void)
{
    GPIOB_ModeCfg(GPIO_Pin_0, GPIO_ModeOut_PP_5mA); // LED RED
    GPIOB_ModeCfg(GPIO_Pin_4, GPIO_ModeOut_PP_5mA); // ETH GREEN LED
    GPIOB_ModeCfg(GPIO_Pin_7, GPIO_ModeOut_PP_5mA); // ETH YELLOW LED

    bsp_led_off(0);
    bsp_led_off(1);
    bsp_led_off(2);

    return 0;
}

/**
 * @}
 */

/******************* (C)COPYRIGHT 2020 ***** END OF FILE *********************/
